package com.xlf.service.base.controller.admin;

import com.xlf.common.core.annotation.Anonymous;
import com.xlf.common.core.pojo.mode.AjaxResult;
import com.xlf.common.core.pojo.mode.BaseController;
import com.xlf.pojo.base.Problem;
import com.xlf.pojo.base.ProblemList;
import com.xlf.service.base.service.ProblemService;
import com.xlf.service.base.service.importProblem.impl.FpsProblemImportService;
import com.xlf.service.base.service.importProblem.impl.ProblemImportService;
import com.xlf.service.base.service.importProblem.impl.QDUOJProblemImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @Author xlf 2734029211@qq.com
 * @Date 2023/11/23 16:05
 * @Description: TODO 题目管理
 * @Version 1.0
 */
@RestController
@RequestMapping("/base/admin/problem")
public class AdminProblemController extends BaseController {

    @Autowired
    ProblemService problemService;

    @Autowired
    ProblemImportService problemImportService;

    @Autowired
    FpsProblemImportService importFpsProblemService;

    @Autowired
    QDUOJProblemImportService qduojProblemImportService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('base:admin:problem:list')")
    public AjaxResult list(Problem problem){
        startPage();
        return success(getDataTable(problemService.getProblemList(problem)));
    }

    @PreAuthorize("@ss.hasPermi('base:admin:problem:saveOrUpdate')")
    @PostMapping("/saveOrUpdate")
    public AjaxResult saveOrUpdate(@RequestBody Problem problem){
        return success(problemService.saveOrUpdate_(problem));
    }


    @PreAuthorize("@ss.hasPermi('base:admin:problem:saveOrUpdate')")
    @PostMapping("/correctionProblem")
    public AjaxResult correctionProblem(@RequestBody List<Problem> problemList){
        problemService.correctionProblem(problemList);
        return success();
    }


    @PreAuthorize("@ss.hasPermi('base:admin:problem:saveOrUpdate')")
    @PostMapping("/copyProblem")
    public AjaxResult copyProblem(@RequestBody List<Long> ids){
        problemService.copyProblem(ids);
        return success();
    }

    @PreAuthorize("@ss.hasPermi('base:admin:problem:import')")
    @PostMapping("/importProblem")
    public AjaxResult importProblem(@RequestParam("file") MultipartFile file) {
        problemImportService.importProblem(file);
        return success();
    }

    @PreAuthorize("@ss.hasPermi('base:admin:problem:import')")
    @PostMapping("/importFpsProblem")
    public AjaxResult importFpsProblem(@RequestParam("file") MultipartFile file) {
        importFpsProblemService.importProblem(file);
        return success();
    }

    @Anonymous
    @PostMapping("/importQProblem")
    public AjaxResult importQProblem(@RequestBody String path) {
        qduojProblemImportService.test(path);
        return success();
    }




    @PreAuthorize("@ss.hasPermi('base:admin:problem:query')")
    @GetMapping("/query/{id}")
    public AjaxResult query(@PathVariable(value = "id") Long id){
        return success(problemService.getProblem(id));
    }

    @DeleteMapping("/delete")
    public AjaxResult delete(@RequestBody List<Long> ids){
        problemService.delete(ids);
        return success("删除成功！");
    }

    @PostMapping("/export")
    public AjaxResult export(@RequestBody List<Long> ids){
        problemService.exportProblem(ids);
        return success("导出成功！");
    }



    @PutMapping("/disabled")
    @PreAuthorize("@ss.hasPermi('base:admin:problemList:saveOrUpdate')")
    public AjaxResult updateStatus(@RequestBody Problem problem){
        return success(problemService.updateStatus(problem));
    }


}
